package com.enjoyor.health.HGPT.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.enjoyor.health.HGPT.core.dto.ReservationConfigNumDto;
import com.enjoyor.health.HGPT.core.entity.ReservationConfiguration;
import com.enjoyor.health.HGPT.core.mapper.ReservationConfigurationMapper;
import com.enjoyor.health.HGPT.core.service.IReservationConfigurationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author enjoyor
 * @since 2023-10-31
 */
@Service
public class ReservationConfigurationServiceImpl extends ServiceImpl<ReservationConfigurationMapper, ReservationConfiguration> implements IReservationConfigurationService {

    @Override
    public List<ReservationConfiguration> getByType(String packageType) {
        QueryWrapper<ReservationConfiguration> queryWrapper = Wrappers.query();
        queryWrapper.eq(StringUtils.isNotBlank(packageType),"package_type", StringUtils.isNotBlank(packageType)?Integer.parseInt(packageType):null);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<ReservationConfiguration> getByWeekDay(String weekDay) {
        QueryWrapper<ReservationConfiguration> queryWrapper = Wrappers.query();
        queryWrapper.eq("weekday", Integer.parseInt(weekDay));
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public int deleteByWeekDay(Integer weekDay, Integer packageType) {
        QueryWrapper<ReservationConfiguration> queryWrapper = Wrappers.query();
        queryWrapper.eq("weekday", weekDay)
                        .eq(packageType !=null, "package_type", packageType);
        return baseMapper.delete(queryWrapper);
    }

    @Override
    public List<ReservationConfigNumDto> getSumByPackageType(String packageType) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("package_type", Integer.parseInt(packageType));
        return baseMapper.getSumByType(map);
    }

    @Override
    public List<ReservationConfigNumDto> getPeriodSumByPackageType(Integer weekDay, String packageType) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("package_type", Integer.parseInt(packageType));
        map.put("weekday", weekDay);
        return baseMapper.getPeriodSumByType(map);
    }
}
